﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TeacherManagement.ascx.cs" Inherits="TeachingAffairsManagementSystem.UserControl.RightContent.Admin.TeacherManagement" %>
<%@ Register Src="~/WebControl/AlertBox.ascx" TagPrefix="uc1" TagName="AlertBox" %>


<uc1:AlertBox runat="server" ID="Alert"/>
<div id="search">
    <div class="form-group">
        <div class="input-group">
            <asp:TextBox ID="TBSearch" runat="server" CssClass="form-control"></asp:TextBox>
            <div class="input-group-btn">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">查询 <span class="caret"></span></button>
                <ul class="dropdown-menu">
                    <li>
                        <asp:LinkButton ID="LBSearchAll" runat="server" OnClick="LBSearchAll_Click">全部</asp:LinkButton>
                    </li>
                    <li>
                        <asp:LinkButton ID="LBSearchS_ID" runat="server" OnClick="LBSearchT_ID_Click">教师ID</asp:LinkButton>
                    </li>
                    <li>
                        <asp:LinkButton ID="LBSearchUsername" runat="server" OnClick="LBSearchUsername_OnClick">用户名</asp:LinkButton>
                    </li>
                    <li>
                        <asp:LinkButton ID="LBSearchEmail" runat="server" OnClick="LBSearchEmail_OnClick">邮箱</asp:LinkButton>
                    </li>
                    <li>
                        <asp:LinkButton ID="LBSearchS_Name" runat="server" OnClick="LBSearchS_Name_OnClick">姓名</asp:LinkButton>
                    </li>
                </ul>
            </div>

        </div>
    </div>
</div>

<div id="gridview">
    <div class="form-group">
        <asp:GridView ID="GVTeacher" runat="server" AutoGenerateColumns="False" DataKeyNames="t_id" DataSourceID="DSTeacher" OnRowUpdated="GVTeacher_RowUpdated" OnRowUpdating="GVTeacher_RowUpdating" ShowHeaderWhenEmpty="True" OnRowCommand="GVTeacher_RowCommand" CssClass="table table-bordered table-hover" AllowPaging="True" AllowSorting="True" PageSize="8">
            <Columns>
                <asp:BoundField DataField="t_id" HeaderText="教师ID" ReadOnly="True" SortExpression="t_id"/>
                <asp:TemplateField HeaderText="用户名" SortExpression="username">
                    <EditItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("username") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("username") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="密码" SortExpression="password">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("password") %>' CssClass="form-control"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("password") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="邮箱" SortExpression="email">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("email") %>' CssClass="form-control"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("email") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="姓名" SortExpression="name">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("name") %>' CssClass="form-control"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label5" runat="server" Text='<%# Bind("name") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="性别" SortExpression="gender">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("gender") %>' CssClass="form-control" Width="65px">
                            <asp:ListItem>男</asp:ListItem>
                            <asp:ListItem>女</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("gender") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="create_time" HeaderText="创建时间" ReadOnly="True" SortExpression="create_time"/>
                <asp:ButtonField CommandName="LookUpLesson" Text="查看开课"/>
                <asp:TemplateField ShowHeader="False">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="更新"></asp:LinkButton>
                        &nbsp;
                        <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Delete" Text="删除" OnClientClick="return confirm('确定要删除吗？')"></asp:LinkButton>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Edit" Text="编辑"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>

            <EmptyDataTemplate>
                无结果
            </EmptyDataTemplate>

        </asp:GridView>
    </div>
</div>

<div id="insert">
    <div class="form-group">
        <table class="table table-bordered table-hover">
            <tr>
                <td>用户名</td>
                <td>密码</td>
                <td>邮箱</td>
                <td>姓名</td>
                <td>性别</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:TextBox CssClass="form-control" ID="TBUsername" runat="server" MaxLength="45"></asp:TextBox>
                </td>
                <td>
                    <asp:TextBox CssClass="form-control" ID="TBPassword" runat="server" MaxLength="45"></asp:TextBox>
                </td>
                <td>
                    <asp:TextBox CssClass="form-control" ID="TBEmail" runat="server" MaxLength="45" TextMode="Email"></asp:TextBox>
                </td>
                <td>
                    <asp:TextBox CssClass="form-control" ID="TBName" runat="server" MaxLength="45"></asp:TextBox>
                </td>
                <td>
                    <asp:DropDownList CssClass="form-control" ID="DLGender" runat="server" Width="65px">
                        <asp:ListItem Selected="True">男</asp:ListItem>
                        <asp:ListItem>女</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:Button CssClass="btn btn-default" ID="BtnInsert" runat="server" Text="插入" ValidationGroup="insert" OnClick="BtnInsert_Click"/>
                </td>
            </tr>
        </table>
    </div>
</div>


<asp:SqlDataSource ID="DSTeacher" runat="server"
                   ConnectionString="<%$ ConnectionStrings:sitedbConnectionString %>"
                   DeleteCommand="DELETE FROM teacher WHERE t_id = ?"
                   ProviderName="<%$ ConnectionStrings:sitedbConnectionString.ProviderName %>"
                   SelectCommand="SELECT * FROM teacher ORDER BY t_id DESC"
                   UpdateCommand="UPDATE teacher SET password = ?, email = ?, name = ?, gender = ? WHERE t_id = ?"
                   InsertCommand="INSERT INTO teacher (username, password, email, name, gender) VALUES (?, ?, ?, ?, ?)">
    <DeleteParameters>
        <asp:Parameter Name="t_id" Type="Int32"/>
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="username" Type="String"/>
        <asp:Parameter Name="password" Type="String"/>
        <asp:Parameter Name="email" Type="String"/>
        <asp:Parameter Name="name" Type="String"/>
        <asp:Parameter Name="gender" Type="String"/>
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="password" Type="String"/>
        <asp:Parameter Name="email" Type="String"/>
        <asp:Parameter Name="name" Type="String"/>
        <asp:Parameter Name="gender" Type="String"/>
        <asp:Parameter Name="t_id" Type="Int32"/>
    </UpdateParameters>
</asp:SqlDataSource>